home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
fdform18.zip
/
DISKIO.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-07-21
|
14KB
|
415 lines
{$A+,B-,D+,E-,F+,I-,L+,N-,O+,R-,S-,V-,X+}
UNIT diskio;
INTERFACE
USES dos,auxdos;
TYPE Split = RECORD
O: Word;
S: Word;
END;
TYPE filtyp = FILE OF ARRAY[0..511] OF Byte;
fileptr = ^filtyp;
boottyp = ARRAY[62..511] OF Byte;
TYPE bpbtyp = RECORD
jmp: ARRAY[1..3] OF Byte; {Die ersten drei Bytes für JUMP}
oem: ARRAY[1..8] OF Char; {OEM-Eintrag}
bps: Word; {Bytes pro Sektor}
spc: Byte; {Sektoren pro Cluster}
res: Word; {BOOT-Sektoren}
fat: Byte; {Anzahl der FAT's}
rde: Word; {Basisverzeichniseinträge}
sec: Word; {Gesamtsektoren der Diskette}
mds: Byte; {Media-Deskriptor}
spf: Word; {Sektoren pro FAT}
spt: Word; {Sektoren pro Spur}
hds: Word; {Seiten}
shh: Longint; {Versteckte Sektoren}
lsc: Longint; {Anzahl der Sektoren bei großen Partitionen}
pdn: Word; {Physical Drive Number}
ebs: Byte; {Extended Boot Signature}
vsn: LongInt; {Volume Serial-Number}
vlb: ARRAY[1..11] OF Char; {Volume Label}
fsi: ARRAY[1..8] OF Char; {File System Id}
boot_code: boottyp; {Puffer für BOOT-Code}
END;
bdib = RECORD
flag : Byte; {Bitmapped flags}
dtyp : Byte; {Drive Type}
dflag : Word; {Bitmapped flags}
noc : Word; {Number of cylinders}
mt : Byte; {Media Type}
bpb : ARRAY[0..30] OF Byte; {BPB}
nos : Word; {Number of sectors per track}
sly : ARRAY[0..63] OF RECORD {sector layout}
num: Word; {Sector Number}
siz: Word; {Size of sector}
END;
END;
dos4rw = RECORD {Disk Read/Write Packet}
sector : LongInt; {für Partitionen >=32M}
count : Word;
Transfer : Pointer;
END;
TYPE SectorTyp = Object
data: Pointer;
Start: LongInt;
datalen: Word;
Constructor init(VAR allocated: Boolean);
PROCEDURE Error(lw,rw,err:Byte; VAR er:Boolean; Sector:Longint); virtual;
PROCEDURE DiskRw(rw,lw:Byte; Sector:LongInt; Count:Byte; Transfer:Pointer);
PROCEDURE Readx(lw: Byte; x: LongInt);
PROCEDURE Writex(lw: Byte; x: LongInt);
Destructor Done;
END;
TYPE CylTyp = Object (SectorTyp)
Constructor init(spcyl: Word; VAR allocated: Boolean);
PROCEDURE Readx(lw: Byte; x: Word);
PROCEDURE Writex(lw: Byte; x: Word);
END;
TYPE BootSecTyp = Object(SectorTyp)
bpb: ^bpbtyp;
status: Word;
Media: Byte;
UnknownDrive: Boolean;
dos4: Boolean;
Constructor init(VAR allocated: Boolean);
PROCEDURE Readx(lw: Byte);
PROCEDURE Writex(lw: Byte);
PROCEDURE Remount(lw: Byte);
END;
TYPE STyp = ARRAY[0..0] OF ^SectorTyp;
CTyp = ARRAY[0..0] OF ^CylTyp;
Smtyp = ^Styp;
Cmtyp = ^CTyp;
VAR BootSec : BootSecTyp;
maxsec : Word;
maxcyl : Word;
PROCEDURE CheckDrive(lw:Byte; VAR Status:Word; VAR error1:Boolean; VAR Media:Byte);
PROCEDURE DeallocCyl(Var Cylmem:Cmtyp; Stop:Word);
PROCEDURE DeallocSec(Var Secmem:Smtyp; Stop:Word);
FUNCTION AllocCyl(VAR Cylmem:Cmtyp; Stop:Word): Word;
FUNCTION AllocSec(VAR secmem:Smtyp; stop:Word): Word;
FUNCTION ReadKey: Char;
IMPLEMENTATION
FUNCTION ReadKey:Char; Assembler;
ASM
mov ah,8
int 21h
END;
PROCEDURE Sectortyp.error(lw,rw,err:Byte; VAR er:Boolean; Sector:Longint);
VAR chx: Char;
BEGIN
WITH BootSec DO BEGIN
WriteLn(stderr);
IF rw=0 THEN
Write(stderr,'Read')
ELSE
Write(stderr,'Write');
Write(stderr,'-Error Drive ',chr(lw+$40),': ');
CASE err OF
$00: Write(stderr,'Disk is write protected');
$01: Write(stderr,'Unknown unit');
$02: Write(stderr,'Drive not ready');
$03: Write(stderr,'Unknown command');
$04: Write(stderr,'Bad CRC');
$05: Write(stderr,'Bad request structure length');
$06: Write(stderr,'Seek error');
$07: Write(stderr,'Unknown media type');
$08: Write(stderr,'Sector not found');
$09: Write(stderr,'Printer out of paper');
$0A: Write(stderr,'Write fault');
$0B: Write(stderr,'Read fault');
$0C: Write(stderr,'General failure');
$0D: Write(stderr,'Sharing violation');
$0E: Write(stderr,'Lock violation');
$0F: Write(stderr,'Invalid disk change');
$10: Write(stderr,'FCB unavailable');
$11: Write(stderr,'Sharing buffer overflow');
ELSE Write(stderr,'Unknown error');
END;
Writeln(stderr,'.');
Write(stderr,'Error ',err,': Sector: ',Sector,' ');
IF Sector=0 THEN
WriteLn(stderr,'BOOT-Sector')
ELSE BEGIN
IF (Sector>=1) and (Sector<=bpb^.spf) THEN
WriteLn(stderr,'FAT 1');
IF (Sector>=bpb^.spf+1) and (sector<=Longint(bpb^.spf) shl 1) THEN
WriteLn(stderr,'FAT 2');
END;
REPEAT
Write(stderr,'(A)bort, (R)etry, (I)gnore ? ');
chx:=Upcase(ReadKey); WriteLn(stderr,chx);
UNTIL chx IN ['A','I','R'];
CASE chx OF
'A': Halt(255);
'I': BEGIN
er:=False;
END;
'R': er:=True;
END;
END;
END;
Constructor SectorTyp.init(VAR allocated: Boolean);
BEGIN
allocated:=True;
IF MaxAvail<512 THEN allocated:=False;
IF allocated THEN BEGIN
GetMem(self.data,512);
datalen:=512;
END;
END;
PROCEDURE int2526(rw,lw:Byte; Sector:Longint; Count:Word; Transfer:Pointer; Var flags,rax: Word); Far;
LABEL common;
VAR rwpacket: dos4rw;
BEGIN
IF NOT(BootSec.Dos4) THEN BEGIN
ASM